<%@ page import="java.util.HashMap,common.CommonUtil,java.util.*,common.*" contentType="text/html; charset=utf-8" %>

<%
UserSession userSession = (UserSession)session.getAttribute("user"); 

//String login_id = null;
String user_id = null;
String level = null;
String admin_ent_id = null;

if(userSession!= null){
	//login_id = userSession.getLogin_id();
	user_id = userSession.getUser_id();
	level = userSession.getAdmin_level();
	admin_ent_id = userSession.getEnt_id();
}

HashMap listMap=(HashMap)request.getAttribute("list_map");

HashMap map  = null;
ArrayList list=null;


if (listMap!=null){
    list=(ArrayList)listMap.get("mainContent");
}

String admin_id = null;
String ent_id = null;
String login_id = null;
String login_pw = null;
String login_name = null;
String admin_level = null;
String email = null;
String tel_no = null;
String cell_no = null;

if(list != null){
	if(list.size() > 0){
		admin_id = (String)((HashMap)list.get(0)).get("admin_id");
		ent_id = CommonUtil.nvl((String)((HashMap)list.get(0)).get("ent_id"));
		login_id = Crypto.DecodeBySType((String)((HashMap)list.get(0)).get("login_id"));
		login_pw = Crypto.DecodeBySType((String)((HashMap)list.get(0)).get("login_pw"));
		login_name = (String)((HashMap)list.get(0)).get("login_name");
		admin_level = (String)((HashMap)list.get(0)).get("admin_level");
		email = CommonUtil.nvl((String)((HashMap)list.get(0)).get("email"));
		tel_no = CommonUtil.nvl((String)((HashMap)list.get(0)).get("tel_no"));
		cell_no = CommonUtil.nvl((String)((HashMap)list.get(0)).get("cell_no"));
		
	}
}
String email_arr[] = {"",""}; 
String tel_no_arr[] = {"","",""}; 
String cell_no_arr[] = {"","",""}; 

if(email.split("@").length > 1 && !email.equals("")){
	email_arr = email.split("@");
}

if(tel_no.split("-").length > 1 && !tel_no.equals("")){
	//tel_no_arr = tel_no.split("-");
	for(int i=0;i<tel_no.split("-").length;i++){
		tel_no_arr[i] = tel_no.split("-")[i];
	}
}

if(cell_no.split("-").length > 1 && !cell_no.equals("")){
	//cell_no_arr = cell_no.split("-");
	for(int i=0;i<cell_no.split("-").length;i++){
		cell_no_arr[i] = cell_no.split("-")[i];
	}
}

%>
<jsp:include page="/jsp/common/header.jsp"></jsp:include>
<script language='javascript' src="/js/ajaxutil.js"></script>
<script language='javascript' src="/js/common.js"></script>
<script language='javascript' src="/js/validate.js"></script>
<script>

//xml 요청
function getXMLHTTPRequest() {
try {
  req = new XMLHttpRequest();
} catch(err1) {
  try {
  req = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (err2) {
    try {
    req = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (err3) {
      req = false;
    } 
  } 
}
return req;
}


function get_login_chk_request(id){
  
  var http = getXMLHTTPRequest();
  var myurl = '/speaking.pb?gubun=admin&cmd=id_chk&id='+id;
  myRand = parseInt(Math.random()*999999999999999);
  var modurl = myurl+"&rand="+myRand;  
  http.open("get", modurl, false);
  //http.onreadystatechange = useHttpResponse;
  http.send(null);
  if (http.readyState == 4) {
    return trim(http.responseText);
  }else{
   return "";
  }
} 	


function get_login_chk(){
	var id = document.mainform.login_id.value;
	if(id == ''){
		alert('ID가 비어 있습니다.');
		document.mainform.login_id.focus();
		return;
	}
	
	for (i=0;i<id.length;i++)   //한글입력을 방지할때
	  {
	   if(id.charCodeAt(i) > 12592)
	   {
	    alert("아이디는 영문과숫자로 조합된 것만 허용됩니다.");
	    document.mainform.login_id.value="";
	    document.mainform.login_id.focus();
	    return;
	    break;
	   }
	  }
	
	var id_chk_cnt = get_login_chk_request(id);
	
	if(id_chk_cnt==0){
		document.mainform.id_chk.value='Y';
		alert('입력하신 아이디는 사용할 수 있습니다.');
	}else{
		document.mainform.id_chk.value='N';
		alert('이미 등록된 아이디입니다. 다른 아이디를 등록하세요.');
		document.mainform.login_id.focus();
		document.mainform.login_id.value='';
	}
}

function go_input(){
	var frm = document.mainform;	
	
	
	if(frm.login_name.value==''){
		alert('이름이 비어있습니다.');
		frm.login_name.focus();
		return;
	}
	
	if(!CheckStrLen(frm.login_name, 1, 20, "이름")) return false;
	
	if(frm.login_pw.value==''){
		alert('비밀번호가 비어있습니다.');
		frm.login_pw.focus();
		return;
	}
	
	if(frm.login_pw.value!=frm.login_pw2.value){
		alert('비밀번호와 비밀번호 확인값이 일치하지 앖습니다.');
		frm.login_pw.focus();
		return;
	}
	
	if(!CheckEngStrLen(frm.login_pw, 1, 20, "비밀번호")) return false;
	
	if(frm.admin_level.value==''){
		alert('등급을 선택 하세요');
		frm.admin_level.focus();
		return;
	}
	
	<%if(level.equals("3")){ %>
	if(frm.ent_id.value==''){
		alert('기업을 선택 하세요');
		frm.ent_id.focus();
		return;
	}
	<%}%>
	
	frm.email.value = frm.email1.value +'@'+ frm.email2.value ;
	frm.tel_no.value = frm.tel_no1.value +'-'+ frm.tel_no2.value+'-'+ frm.tel_no3.value ;
	frm.cell_no.value = frm.cell_no1.value +'-'+ frm.cell_no2.value +'-'+ frm.cell_no3.value ;
	
	var mailexp = /[a-z0-9]{2,}@[a-z0-9-]{2,}\.[a-z0-9]{2,}/i; 
	if(!mailexp.test(frm.email.value))
	 {
	  alert("이메일형식이 맞지 않습니다.");
	  frm.email1.focus();
	  return;
	 }
	
	if(!CheckEngStrLen(frm.email, 1, 100, "email")) return false;
	
	frm.cmd.value='admin_modify';
	frm.action = '/speaking.pb';
	frm.target= 'hidden_frm';              
	frm.submit();	
}

function go_admin(){
	var frm = document.mainform;	
	frm.cmd.value='admin_main';
	frm.action = '/speaking.pb';
	frm.target= '_self';              
	frm.submit();	
}
function init_admin(){
	form = document.mainform;
	<%if(!ent_id.equals("")){%>
	setSPSelect(form.ent_id_sel,'<%=ent_id%>', '기업선택', 'ent');
	<%}else{%>
	setSPSelect(form.ent_id,'', '기업선택', 'ent');
	<%}%>
}
window.onload = init_admin;
</script>

<jsp:include page="/jsp/common/top.jsp"></jsp:include>
<jsp:include page="/jsp/common/submenu.jsp"><jsp:param name="submenu_id" value="admin_main" /><jsp:param name="submenu_idx" value="1" /></jsp:include>

<form name="mainform"  method="post" action = "/speaking.pb" >
	<div id="bodyContainer">
        <div id="contents">
          <jsp:include page="/jsp/common/submenu_list.jsp"><jsp:param name="submenu_id" value="admin_main" /><jsp:param name="submenu_idx" value="3" /></jsp:include>
          
          
          <div class="boxContainer">
            <dl title="관리자수정">
              <dt>관리자수정</dt>
            </dl>
            <table class="setupTb">
            
              <tr>
                <th>ID</th>
                <td><%= login_id %> <input type="hidden" name="login_id" id="login_id"  value="<%= login_id%>"/></td>
              </tr>
              <tr>
                <th>이름</th>
                <td><input type="text" name="login_name" id="login_name" style="width:200px" value="<%= login_name%>"/></td>
              </tr>
              <tr>
                <th>비밀번호</th>
                <td><input type="password" name="login_pw" id="login_pw" style="width:200px" value="<%= login_pw %>"/></td>
              </tr>
               <tr>
                <th>비밀번호 확인</th>
                <td><input type="password" name="login_pw2" id="login_pw2" style="width:200px" value="<%= login_pw %>"/></td>
              </tr>
              <%if(level.equals("1")){ %>
              <tr>
                <th>등급</th>
                <td><select name="admin_level" id="admin_level">
                  <option value=''>선택</option>
                  <option value='1' <%=(admin_level.equals("1"))?"selected":"" %>>전체관리자</option>
                  <option value='2' <%=(admin_level.equals("2"))?"selected":"" %>>부운영자</option>
                  <option value='3' <%=(admin_level.equals("3"))?"selected":"" %>>기업관리자</option>
                  <option value='4' <%=(admin_level.equals("4"))?"selected":"" %>>Rater</option>
                  <option value='5' <%=(admin_level.equals("5"))?"selected":"" %>>기업회원관리자</option>
                </select></td>
              </tr>
              <%}else{ %>
                <input type="hidden" name="admin_level" id="admin_level" value="<%=admin_level %>" />
              <%} %>
              
              <tr>
                <th>기업</th>
                <td><select name="<%=(!ent_id.equals(""))?"ent_id_sel":"ent_id" %>" id="<%=(!ent_id.equals(""))?"ent_id_sel":"ent_id" %>" <%=(!ent_id.equals(""))?"disabled":"" %>>
                  <option value=''>기업선택</option>                  
                </select></td>
              </tr>
              
              <%if(!ent_id.equals("")){%>
              <input type="hidden" name="ent_id" id="ent_id" value="<%=ent_id %>" />
              <%} %>
              
              <!-- 
              <tr>
                <th>email</th>
                <td><input type="text" name="email" id="email" style="width:200px" value="<%= email%>"/></td>
              </tr>
              <tr>
                <th>연락처</th>
                <td><input type="text" name="tel_no" id="tel_no" style="width:200px" value="<%= tel_no%>" onkeydown="MaskPhon(this);" onkeyup="MaskPhon(this);"  /></td>
              </tr>
              <tr>
                <th>휴대폰</th>
                <td><input type="text" name="cell_no" id="cell_no" style="width:200px" value="<%= cell_no%>" onkeydown="MaskPhon(this);" onkeyup="MaskPhon(this);" /></td>
              </tr>  
              -->
              <tr>
                <th>email</th>
                <td>
                <input type="hidden" name="email" id="email" style="width:100px" value="<%= email%>"/>
                <input type="text" name="email1" id="email1" style="width:100px" value="<%= email_arr[0]%>" onkeydown="eng_chk(this);" onkeyup="eng_chk(this);" />
                @
                <input type="text" name="email2" id="email2" style="width:100px" value="<%= email_arr[1]%>" onkeydown="eng_chk(this);" onkeyup="eng_chk(this);" />
                <select name="email_list" onchange="document.mainform.email2.value=this.value" style="height:17px" >
                  <option value="" >직접입력</option>
                  <option value="hanmail.net" >hanmail.net</option>
			      <option value="naver.com" >naver.com</option>
			      <option value="netian.com" >netian.com</option>
			      <option value="dreamwiz.com" >dreamwiz.com</option>
			      <option value="lycos.co.kr" >lycos.co.kr</option>
			      <option value="yahoo.co.kr" >yahoo.co.kr</option>
			      <option value="chollian.net" >chollian.net</option>
			      <option value="orgio.net" >orgio.net</option>
			      <option value="korea.com" >korea.com</option>
			      <option value="freechal.com" >freechal.com</option>
			      <option value="hotmail.com" >hotmail.com</option>
			      <option value="unitel.co.kr" >unitel.co.kr</option>
			      <option value="nate.com" >nate.com</option>
			      <option value="empal.com" >empal.com</option>
			      <option value="nownuri.net" >nownuri.net</option>
			      <option value="hanafos.com" >hanafos.com</option>
			      <option value="kornet.net" >kornet.net</option>
			      <option value="arreo.com" >arreo.com</option>
			      <option value="paran.com" >paran.com</option>
			      <option value="hitel.net" >hitel.net</option>
			      <option value="hanmir.com" >hanmir.com</option>			                      
                </select>
                </td>
              </tr>
              <tr>
                <th>연락처</th>
                <td>
                <input type="hidden" name="tel_no" id="tel_no" style="width:50px" value="<%= tel_no%>"/>
                <input type="text" name="tel_no1" id="tel_no1" style="width:50px" value="<%= tel_no_arr[0]%>" maxlength=4 onkeydown="num_chk(this);" onkeyup="num_chk(this);" />
                -
                <input type="text" name="tel_no2" id="tel_no2" style="width:50px" value="<%= tel_no_arr[1]%>" maxlength=4 onkeydown="num_chk(this);" onkeyup="num_chk(this);" />
                -
                <input type="text" name="tel_no3" id="tel_no3" style="width:50px" value="<%= tel_no_arr[2]%>" maxlength=4 onkeydown="num_chk(this);" onkeyup="num_chk(this);" />
                </td>
              </tr>
              <tr>
                <th>휴대폰</th>
                <td>
                <input type="hidden" name="cell_no" id="cell_no" style="width:50px" value="<%= cell_no%>"/>
                <input type="text" name="cell_no1" id="cell_no1" style="width:50px" value="<%= cell_no_arr[0]%>" maxlength=4 onkeydown="num_chk(this);" onkeyup="num_chk(this);" />
                -
                <input type="text" name="cell_no2" id="cell_no2" style="width:50px" value="<%= cell_no_arr[1]%>" maxlength=4 onkeydown="num_chk(this);" onkeyup="num_chk(this);" />
                -
                <input type="text" name="cell_no3" id="cell_no3" style="width:50px" value="<%= cell_no_arr[2]%>" maxlength=4 onkeydown="num_chk(this);" onkeyup="num_chk(this);" />
                </td>
              </tr>             
            </table>
            <p><a href="#" onclick="go_input()"><img src="img/btn_modify.gif" alt="수정" width="49" height="20" /></a> <a href="#" onclick="go_admin()"><img src="img/btn_list.gif" alt="목록" width="49" height="20" /></a> </p>
            
          </div>
          
        </div>
      </div>


<input type="hidden" name="cmd" value="">
<input type="hidden" name="user_id" value="<%=user_id %>">
<input type="hidden" name="admin_id" value="<%=admin_id %>">
<input type="hidden" name="id_chk" value="N">

</form>

<iframe name='hidden_frm'  width='0' height='0' SCROLLING='AUTO' frameborder='0'></iframe>
<jsp:include page="/jsp/common/footer.jsp"></jsp:include>
<jsp:include page="/jsp/common/bottom.jsp"></jsp:include>
